# Setup Versions
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/Version.h)
install (FILES  ${CMAKE_CURRENT_BINARY_DIR}/Version.h DESTINATION include/toadlet/tadpole)


# Source files for toadlet_tadpole
set (TADPOLE_SRC
	ArchiveManager.cpp
	AudioBufferManager.cpp
	BufferManager.cpp
	DecalShadowSceneRenderer.cpp
	Engine.cpp
	Font.cpp
	FontManager.cpp
	MaterialManager.cpp
	MathFormatter.cpp
	Mesh.cpp
	MeshManager.cpp
	NodeManager.cpp
	Noise.cpp
	RenderableSet.cpp
	ResourceManager.cpp
	Scene.cpp
	SceneRenderer.cpp
	ShaderManager.cpp
	ShadowMappedSceneRenderer.cpp
	Skeleton.cpp
	TransformKeyFrame.cpp
	TransformSequence.cpp
	TransformTrack.cpp
	TextureManager.cpp
	Version.cpp
)

set (TADPOLE_ANIMATION_SRC
	animation/Controller.cpp
	animation/CameraProjectionAnimation.cpp
	animation/NodePathAnimation.cpp
	animation/SkeletonAnimation.cpp
)

set (TADPOLE_BSP_SRC
	bsp/BSP30Map.cpp
	bsp/BSP30Node.cpp
	bsp/BSP30Handler.cpp
)

set (TADPOLE_HANDLER_SRC
	handler/TMSHHandler.cpp
	handler/WADArchive.cpp
)

set (TADPOLE_HANDLER_XML_SRC
	handler/XANMHandler.cpp
	handler/XMLMeshUtilities.cpp
	handler/XMATHandler.cpp
	handler/XMSHHandler.cpp
)

set (TADPOLE_HANDLER_FREETYPE_SRC
	handler/FreeTypeHandler.cpp
)

set (TADPOLE_HANDLER_PLATFORM_OSX_SRC
	handler/platform/osx/OSXBundleArchive.mm
	handler/platform/osx/OSXFontHandler.mm
	handler/platform/osx/OSXTextureHandler.mm
)

set (TADPOLE_HANDLER_PLATFORM_WIN32_SRC
	handler/platform/win32/Win32ResourceArchive.cpp
)

set (TADPOLE_HANDLER_PLATFORM_WIN32_GDIPLUS_SRC
	handler/platform/win32/Win32FontHandler.cpp
	handler/platform/win32/Win32TextureHandler.cpp
)

set (TADPOLE_MATERIAL_SRC
	material/Material.cpp
	material/RenderPass.cpp
	material/RenderPath.cpp
	material/RenderVariableSet.cpp
)

set (TADPOLE_NODE_SRC
	node/AnaglyphCameraNode.cpp
	node/AudioNode.cpp
	node/CameraNode.cpp
	node/CameraAlignedNode.cpp
	node/LabelNode.cpp
	node/LightNode.cpp
	node/MeshNode.cpp
	node/MeshNodeSkeleton.cpp
	node/Node.cpp
	node/ParentNode.cpp
	node/ParticleNode.cpp
	node/PartitionNode.cpp
	node/SpriteNode.cpp
)

set (TADPOLE_SENSOR_SRC
	sensor/BoundingVolumeSensor.cpp
	sensor/InterfaceSensor.cpp
	sensor/NameSensor.cpp
	sensor/PotentiallyVisibleSensor.cpp
	sensor/Sensor.cpp
	sensor/SensorResults.cpp
	sensor/TypeSensor.cpp
)

set (TADPOLE_STUDIO_SRC
	studio/SpriteHandler.cpp
	studio/SpriteModelNode.cpp
	studio/StudioHandler.cpp
	studio/StudioModelNode.cpp
)

set (TADPOLE_TERRAIN_SRC
	terrain/TerrainNode.cpp
	terrain/TerrainPatchNode.cpp
)


# Headers
set (TADPOLE_HEADERS
	Attachable.h
	ArchiveManager.h
	AudioBufferManager.h
	Bound.h
	BufferManager.h
	Collision.h
	Colors.h
	ContextListener.h
	DecalShadowSceneRenderer.h
	Engine.h
	Font.h
	FontData.h
	FontManager.h
	MaterialManager.h
	MathFormatter.h
	Mesh.h
	MeshManager.h
	NodeManager.h
	Noise.h
	Renderable.h
	RenderListener.h
	ResourceHandler.h
	ResourceHandlerData.h
	ResourceManager.h
	RenderableSet.h
	Scene.h
	SceneRenderer.h
	ShaderManager.h
	ShadowMappedSceneRenderer.h
	Skeleton.h
	TextureManager.h
	Traceable.h
	Transform.h
	Transformable.h
	TransformKeyFrame.h
	TransformSequence.h
	TransformTrack.h
	Types.h
	UpdateListener.h
	VertexFormats.h
	Version.h
	Visible.h
)

set (TADPOLE_ANIMATION_HEADERS
	animation/Animatable.h
	animation/Controller.h
	animation/ControllerFinishedListener.h
	animation/CameraProjectionAnimation.h
	animation/MaterialLightEffectAnimation.h
	animation/NodePathAnimation.h
	animation/SkeletonAnimation.h
)

set (TADPOLE_BSP_HEADERS
	bsp/BSP30Handler.h
	bsp/BSP30Map.h
	bsp/BSP30Node.h
	bsp/BSP30Types.h
)

set (TADPOLE_HANDLER_HEADERS
	handler/AudioBufferHandler.h
	handler/BMPHandler.h
	handler/GIFHandler.h
	handler/JPEGHandler.h
	handler/TMSHHandler.h
	handler/PNGHandler.h
	handler/SPRHandler.h
	handler/TGAHandler.h
	handler/TPKGHandler.h
	handler/WADArchive.h
	handler/WADHandler.h
	handler/ZIPHandler.h
)

set (TADPOLE_HANDLER_XML_HEADERS
	handler/XANMHandler.h
	handler/XMLMeshUtilities.h
	handler/XMATHandler.h
	handler/XMSHHandler.h
)

set (TADPOLE_HANDLER_FREETYPE_HEADERS
	handler/FreeTypeHandler.h
)

set (TADPOLE_HANDLER_PLATFORM_OSX_HEADERS
	handler/platform/osx/OSXBundleArchive.h
	handler/platform/osx/OSXFontHandler.h
	handler/platform/osx/OSXTextureHandler.h
) 

set (TADPOLE_HANDLER_PLATFORM_WIN32_HEADERS
	handler/platform/win32/Win32ResourceArchive.h
)

set (TADPOLE_HANDLER_PLATFORM_WIN32_GDIPLUS_HEADERS
	handler/platform/win32/StreamIStream.h
	handler/platform/win32/Win32FontHandler.h
	handler/platform/win32/Win32TextureHandler.h
)

set (TADPOLE_MATERIAL_HEADERS
	material/Material.h
	material/RenderPass.h
	material/RenderPath.h
	material/RenderVariable.h
	material/RenderVariables.h
	material/RenderVariableSet.h
	material/SceneParameters.h
)

set (TADPOLE_NODE_HEADERS
	node/AnaglyphCameraNode.h
	node/AudioNode.h
	node/CameraNode.h
	node/CameraAlignedNode.h
	node/LabelNode.h
	node/LightNode.h
	node/MeshNode.h
	node/MeshNodeSkeleton.h
	node/Node.h
	node/NodeAttacher.h
	node/NodeListener.h
	node/NodeResource.h
	node/ParentNode.h
	node/ParticleNode.h
	node/PartitionNode.h
	node/SpriteNode.h
)

set (TADPOLE_SENSOR_HEADERS
	sensor/BoundingVolumeSensor.h
	sensor/InterfaceSensor.h
	sensor/NameSensor.h
	sensor/PotentiallyVisibleSensor.h
	sensor/Sensor.h
	sensor/SensorResults.h
	sensor/SensorResultsListener.h
	sensor/TypeSensor.h
)

set (TADPOLE_STUDIO_HEADERS
	studio/SpriteHandler.h
	studio/SpriteModel.h
	studio/SpriteModelNode.h
	studio/SpriteTypes.h
	studio/StudioHandler.h
	studio/StudioModel.h
	studio/StudioModelNode.h
	studio/StudioTypes.h
)

set (TADPOLE_TERRAIN_HEADERS
	terrain/TerrainNodeDataSource.h
	terrain/TerrainNodeListener.h
	terrain/TerrainNode.h
	terrain/TerrainPatchNode.h
)


# Bundle source
source_group ("Source Files\\\\animation" FILES ${TADPOLE_ANIMATION_SRC})
source_group ("Source Files\\\\handler" FILES ${TADPOLE_HANDLER_SRC})
source_group ("Source Files\\\\material" FILES ${TADPOLE_MATERIAL_SRC})
source_group ("Source Files\\\\node" FILES ${TADPOLE_NODE_SRC})
source_group ("Source Files\\\\sensor" FILES ${TADPOLE_SENSOR_SRC})
source_group ("Source Files\\\\terrain" FILES ${TADPOLE_TERRAIN_SRC})


# Bundle headers
source_group ("Header Files\\\\animation" FILES ${TADPOLE_ANIMATION_HEADERS})
source_group ("Header Files\\\\handler" FILES ${TADPOLE_HANDLER_HEADERS})
source_group ("Header Files\\\\material" FILES ${TADPOLE_MATERIAL_HEADERS})
source_group ("Header Files\\\\node" FILES ${TADPOLE_NODE_HEADERS})
source_group ("Header Files\\\\sensor" FILES ${TADPOLE_SENSOR_HEADERS})
source_group ("Header Files\\\\terrain" FILES ${TADPOLE_TERRAIN_HEADERS})


# Source headers and namespaces
set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_ANIMATION_SRC} ${TADPOLE_HANDLER_SRC} ${TADPOLE_MATERIAL_SRC} ${TADPOLE_NODE_SRC} ${TADPOLE_SENSOR_SRC} ${TADPOLE_TERRAIN_SRC})

# TODO: The handlers/ subdirectory is going to become a plugin system, and so they are NOT included in the aggregate header files
# This is true for all handler/ subdirectory files
set (TADPOLE_HEADERS ${TADPOLE_HEADERS} ${TADPOLE_ANIMATION_HEADERS} ${TADPOLE_MATERIAL_HEADERS} ${TADPOLE_NODE_HEADERS} ${TADPOLE_SENSOR_HEADERS} ${TADPOLE_TERRAIN_HEADERS})
set (TADPOLE_NAMESPACES ${TADPOLE_NAMESPACES} animation material node sensor terrain)

if (NOT TOADLET_FIXED_POINT)
	source_group ("Source Files\\\\bsp" FILES ${TADPOLE_BSP_SRC})
	source_group ("Header Files\\\\bsp" FILES ${TADPOLE_BSP_HEADERS})
	source_group ("Source Files\\\\studio" FILES ${TADPOLE_STUDIO_SRC})
	source_group ("Header Files\\\\studio" FILES ${TADPOLE_STUDIO_HEADERS})
	set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_BSP_SRC} ${TADPOLE_STUDIO_SRC})
	set (TADPOLE_HEADERS ${TADPOLE_HEADERS} ${TADPOLE_BSP_HEADERS} ${TADPOLE_STUDIO_HEADERS})
	set (TADPOLE_NAMESPACES ${TADPOLE_NAMESPACES} bsp studio)
endif (NOT TOADLET_FIXED_POINT)


# Setup dependecy specific files and libraries
# Freetype is not required on OSX
if (NOT TOADLET_PLATFORM_OSX)
	find_package (Freetype)
	if (FREETYPE_FOUND)
		set (TOADLET_HAS_FREETYPE ON PARENT_SCOPE)
		include_directories (${FREETYPE_INCLUDE_DIRS})
		source_group ("Source Files\\\\handler" FILES ${TADPOLE_HANDLER_FREETYPE_SRC})
		source_group ("Header Files\\\\handler" FILES ${TADPOLE_HANDLER_FREETYPE_HEADERS})
		set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_HANDLER_FREETYPE_SRC})

		# Libraries
		set (TADPOLE_LIBS ${FREETYPE_LIBRARIES})
		add_library (libfreetype_s STATIC IMPORTED)
		if (TOADLET_PLATFORM_POSIX)
			string (REPLACE ".so" ".a" FREETYPE_A ${FREETYPE_LIBRARY})
			if (EXISTS ${FREETYPE_A})
				set (FREETYPE_LIBRARY ${FREETYPE_A})
			endif (EXISTS ${FREETYPE_A})
		endif (TOADLET_PLATFORM_POSIX)
		set_property (TARGET libfreetype_s PROPERTY IMPORTED_LOCATION ${FREETYPE_LIBRARY})
		set (TADPOLE_DEFS_S TOADLET_LIBFREETYPE_NAME="${FREETYPE_LIBRARY}")
		set (TADPOLE_LIBS_S libfreetype_s)
	endif (FREETYPE_FOUND)
endif (NOT TOADLET_PLATFORM_OSX)

find_package (MXML)
if (MXML_FOUND)
	# Files
	set (TOADLET_HAS_MXML ON PARENT_SCOPE)
	include_directories (${MXML_INCLUDE_DIR})
	source_group ("Source Files\\\\handler" FILES ${TADPOLE_HANDLER_XML_SRC})
	source_group ("Header Files\\\\handler" FILES ${TADPOLE_HANDLER_XML_HEADERS})
	set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_HANDLER_XML_SRC})

	# Libraries
	set (TADPOLE_LIBS ${TADPOLE_LIBS} ${MXML_LIBRARY})
	add_library (libmxml_s STATIC IMPORTED)
	if (TOADLET_PLATFORM_POSIX)
		string (REPLACE ".so" ".a" MXML_A ${MXML_LIBRARY})
		if (EXISTS ${MXML_A})
			set (MXML_LIBRARY ${MXML_A})
		endif (EXISTS ${MXML_A})
	endif (TOADLET_PLATFORM_POSIX)
	set_property (TARGET libmxml_s PROPERTY IMPORTED_LOCATION ${MXML_LIBRARY})
	set (TADPOLE_DEFS_S ${TADPOLE_DEFS_S} TOADLET_LIBMXML_NAME="${MXML_LIBRARY}")
	set (TADPOLE_LIBS_S ${TADPOLE_LIBS_S} libmxml_s)

	# OSX requires a specific link to mxml
	if (TOADLET_PLATFORM_OSX)
		set (STATIC_LIB_PROPS ${STATIC_LIB_PROPS} STATIC_LIBRARY_FLAGS ${MXML_LIBRARY})	
	endif (TOADLET_PLATFORM_OSX)
endif (MXML_FOUND)

# Platform specific files
if (TOADLET_PLATFORM_OSX)
	source_group ("Source Files\\\\handler\\\\platform\\\\osx" FILES ${TADPOLE_HANDLER_PLATFORM_OSX_SRC})
	source_group ("Header Files\\\\handler\\\\platform\\\\osx" FILES ${TADPOLE_HANDLER_PLATFORM_OSX_HEADERS})
	set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_HANDLER_PLATFORM_OSX_SRC})
	if (TOADLET_PLATFORM_IOS)
		find_library (UIKIT_LIBS UIKit)
		set (TADPOLE_LIBS_S ${TADPOLE_LIBS_S} ${UIKIT_LIBS})
		set (TADPOLE_LIBS ${TADPOLE_LIBS} ${UIKIT_LIBS})
	else (TOADLET_PLATFORM_IOS)
		find_library (APPKIT_LIBS AppKit)
		set (TADPOLE_LIBS_S ${TADPOLE_LIBS_S} ${APPKIT_LIBS})	
		set (TADPOLE_LIBS ${TADPOLE_LIBS} ${APPKIT_LIBS})	
	endif (TOADLET_PLATFORM_IOS)
elseif (TOADLET_PLATFORM_WIN32)
	find_package (GDIPLUS)
	if (GDIPLUS_FOUND)
		set (TOADLET_HAS_GDIPLUS ON PARENT_SCOPE)
		include_directories (${GDIPLUS_INCLUDE_PATH})
		source_group ("Source Files\\\\handler\\\\platform\\\\win32" FILES ${TADPOLE_HANDLER_PLATFORM_WIN32_GDIPLUS_SRC})
		source_group ("Header Files\\\\handler\\\\platform\\\\win32" FILES ${TADPOLE_HANDLER_PLATFORM_WIN32_GDIPLUS_HEADERS})
		set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_HANDLER_PLATFORM_WIN32_GDIPLUS_SRC})
	endif (GDIPLUS_FOUND)
	source_group ("Source Files\\\\handler\\\\platform\\\\win32" FILES ${TADPOLE_HANDLER_PLATFORM_WIN32_SRC})
	source_group ("Header Files\\\\handler\\\\platform\\\\win32" FILES ${TADPOLE_HANDLER_PLATFORM_WIN32_HEADERS})
	set (TADPOLE_SRC ${TADPOLE_SRC} ${TADPOLE_HANDLER_PLATFORM_WIN32_SRC})
endif (TOADLET_PLATFORM_OSX)


# Give the headers and namespaces parent scope for inclusion into the master tadpole.h file
set (TADPOLE_HEADERS ${TADPOLE_HEADERS} PARENT_SCOPE)
set (TADPOLE_NAMESPACES ${TADPOLE_NAMESPACES} PARENT_SCOPE)


# Dynamic library
if (NOT TOADLET_PLATFORM_IOS)
	add_library (toadlet_tadpole SHARED ${TADPOLE_SRC} ${TADPOLE_HEADERS})
	set_target_properties (toadlet_tadpole PROPERTIES ${DYNAMIC_LIB_PROPS})
	target_link_libraries (toadlet_tadpole toadlet_egg toadlet_peeper toadlet_ribbit ${TADPOLE_LIBS})
	install (TARGETS toadlet_tadpole DESTINATION lib)
endif (NOT TOADLET_PLATFORM_IOS)


# Static library
add_library (toadlet_tadpole_s STATIC ${TADPOLE_SRC} ${TADPOLE_HEADERS})
set_target_properties (toadlet_tadpole_s PROPERTIES ${STATIC_LIB_PROPS})
set_property (TARGET toadlet_tadpole_s APPEND PROPERTY COMPILE_DEFINITIONS ${TADPOLE_DEFS_S})
target_link_libraries (toadlet_tadpole_s toadlet_egg_s toadlet_peeper_s toadlet_ribbit_s ${TADPOLE_LIBS_S})
install (TARGETS toadlet_tadpole_s DESTINATION lib)


# Add plugins
add_subdirectory (plugins/hop)

